import SelectionReplacePlugin from "./main";
import {App, Modal, Setting} from "obsidian";
import {CommonUI, RegexDef} from "./common";

export class ExecuteUI extends Modal {
    plugin: SelectionReplacePlugin;
    commonUI: CommonUI;
    constructor(app: App, plugin: SelectionReplacePlugin) {
        super(app);
        this.plugin = plugin;
        this.commonUI = new CommonUI(this.contentEl, plugin);
    }

    onOpen() {
        this.contentEl.empty();
        this.commonUI.display();
        new Setting(this.contentEl).addButton((cb) => {
            cb.setButtonText("Run (Replace Selection Text)")
                .setCta()
                .onClick(() => {
                    this.plugin.replaceSelectionText();
                });
        }).addButton((cb) => {
            cb.setButtonText("Run (Replace Page Text)")
                .setCta()
                .onClick(() => {
                    this.plugin.replacePageText();
                });
        }).addButton((cb) => {
            cb.setButtonText("Run (Replace Vault Text)")
                .setCta()
                .onClick(() => {
                    this.plugin.replaceVaultText();
                });
        });
    }
}